package com.ruoyi.college.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.college.domain.FirstLevelSubject;
import com.ruoyi.college.service.IFirstLevelSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一级学科管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/college/firstSubject")
public class FirstLevelSubjectController extends BaseController
{
    @Autowired
    private IFirstLevelSubjectService firstLevelSubjectService;

    /**
     * 查询一级学科管理列表
     */
   // @PreAuthorize("@ss.hasPermi('college:firstSubject:list')")
    @GetMapping("/list")
    public TableDataInfo list(FirstLevelSubject firstLevelSubject)
    {
        startPage();
        List<FirstLevelSubject> list = firstLevelSubjectService.selectFirstLevelSubjectList(firstLevelSubject);
        return getDataTable(list);
    }

    /**
     * 导出一级学科管理列表
     */
    @PreAuthorize("@ss.hasPermi('college:firstSubject:export')")
    @Log(title = "一级学科管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirstLevelSubject firstLevelSubject)
    {
        List<FirstLevelSubject> list = firstLevelSubjectService.selectFirstLevelSubjectList(firstLevelSubject);
        ExcelUtil<FirstLevelSubject> util = new ExcelUtil<FirstLevelSubject>(FirstLevelSubject.class);
        util.exportExcel(response, list, "一级学科管理数据");
    }

    /**
     * 获取一级学科管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('college:firstSubject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(firstLevelSubjectService.selectFirstLevelSubjectById(id));
    }

    /**
     * 新增一级学科管理
     */
    @PreAuthorize("@ss.hasPermi('college:firstSubject:add')")
    @Log(title = "一级学科管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirstLevelSubject firstLevelSubject)
    {
        return toAjax(firstLevelSubjectService.insertFirstLevelSubject(firstLevelSubject));
    }

    /**
     * 修改一级学科管理
     */
    @PreAuthorize("@ss.hasPermi('college:firstSubject:edit')")
    @Log(title = "一级学科管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirstLevelSubject firstLevelSubject)
    {
        return toAjax(firstLevelSubjectService.updateFirstLevelSubject(firstLevelSubject));
    }

    /**
     * 删除一级学科管理
     */
    @PreAuthorize("@ss.hasPermi('college:firstSubject:remove')")
    @Log(title = "一级学科管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(firstLevelSubjectService.deleteFirstLevelSubjectByIds(ids));
    }
    /**
     *传入学院id获取该学院下的所有一级学科
     */
    @GetMapping("/getFirstSubjectByCollegeId/{collegeId}")
    public AjaxResult getFirstSubjectByCollegeId(@PathVariable String collegeId)
    {
        //打印获取到的参数
        System.out.println("--------------------------------");
        System.out.println("传入的参数是："+collegeId);
        System.out.println("--------------------------------");

        FirstLevelSubject firstLevelSubject=new FirstLevelSubject();
        firstLevelSubject.setCollegeId(collegeId);
        List<FirstLevelSubject> list = firstLevelSubjectService.selectFirstLevelSubjectList(firstLevelSubject);
    	return success(list);
    }

}
